cmake_minimum_required(VERSION 3.5)
if(POLICY CMP0046)
  cmake_policy(SET CMP0046 NEW)
endif()
if(POLICY CMP0054)
  cmake_policy(SET CMP0054 NEW)
endif()

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX11)
if(NOT COMPILER_SUPPORTS_CXX11)
  message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++17 support. Please use a different C++ compiler.")
endif()

if(USE_libstdcpp)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
  message("-- Warning: forcing libstdc++ (controlled by USE_libstdc++ option in cmake)")
endif()

# compile flags
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -O2")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -D_REENTRANT -fPIC -Wall -Werror")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS OFF) # 禁用编译器扩展
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Werror -fPIC -D_REENTRANT")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -Wall -fPIC -D_REENTRANT")



###############

#find_package(Gflags)
#find_package(Glog)
#include_directories(${GFLAGS_INCLUDE_DIRS} ${GLOG_INCLUDE_DIRS})

# ---[ gflags
#include(CNStream/cmake/FindGFlags.cmake)
#include_directories(${GFLAGS_INCLUDE_DIRS})

# ---[ Opencv
find_package(OpenCV REQUIRED core imgproc highgui features2d)
if(OpenCV_FOUND)
  include_directories(${OpenCV_INCLUDE_DIRS})
  message(STATUS "opencv include: ${OpenCV_INCLUDE_DIRS}")
  message(STATUS "opencv libraries: ${OpenCV_LIBS}")
else()
  message(FATAL_ERROR "opencv not found!")
endif()

##########################ffmpeg
# ---[ FFmpeg 配置优化
# ---[ FFmpeg 配置优化
find_package(PkgConfig REQUIRED) # 确保pkg-config可用
pkg_check_modules(FFMPEG REQUIRED IMPORTED_TARGET
  libavcodec libavformat libavutil libswscale libswresample
)



# 包含其他目录
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common/config)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common/http)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common/json)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common/log)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common/rocketmq)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/httpServer)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/mqProducer)




link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)

if(NOT DEFINED ENV{NEUWARE_HOME})
  set(ENV{NEUWARE_HOME} /usr/local/neuware)
endif()
include_directories("$ENV{NEUWARE_HOME}/include")
link_directories("$ENV{NEUWARE_HOME}/lib64")

aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src srcs)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/common/config common_config_srcs)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/common/http common_http_srcs)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/httpServer http_server_srcs)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/mqProducer mq_producer_srcs)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)



add_executable(testmq ${srcs} ${common_srcs} ${common_config_srcs} ${http_server_srcs} ${mq_producer_srcs})
target_compile_definitions(testmq PUBLIC GLOG_USE_GLOG_EXPORT)
target_link_libraries(testmq

 

  "${CMAKE_SOURCE_DIR}/lib/librocketmq.so" # 动态库
  "${CMAKE_SOURCE_DIR}/lib/librocketmq.a" # 静态库（可选）



)

target_link_libraries(testmq uuid  ${OpenCV_LIBS} pthread dl)
